var xiaotong = function (ele1,ele2,num1,num2) {
    var arr = [
        {id: 1, name: '一一', city: [  
            {id: 101, name: '一一一'},
            {id: 102, name: '一一二'},
            {id: 103, name: '一一三'},
            {id: 104, name: '一一四'}  
        ]},  
        {id: 2, name: '二二', city: [  
            {id: 201, name: '二二一'},
            {id: 202, name: '二二二'},
            {id: 203, name: '二二三'},
            {id: 204, name: '二二四'},
        ]},  
        {id: 3, name: '三三', city: [  
            {id: 301, name: '三三一'},
            {id: 302, name: '三三二'},
            {id: 303, name: '三三三'},
            {id: 304, name: '三三四'},
        ]}  
    ];
    for(var i=0;i<arr.length;i++){
        $(ele1).append("<option value='"+arr[i].id+"'>"+arr[i].name+"</option>")
    }
    $(ele1).on("change",function(){
        var id = $(this).val()-1;
        var name = arr[id].city;
        $(ele2).html("");
        for(var i=0;i<name.length;i++){
            $(ele2).append("<option value='"+name[i].id+"'>"+name[i].name+"</option>")
        }
    })
    if (num1!=""){
        var id = 0;
        $(ele1).children().each(function(){
            if($(this).val() == num1){
                $(this).attr("selected","selected");
                id = $(this).val()-1;
            }
        })
        if(num2!=undefined){
            var name = arr[id].city;
            for(var i=0;i<name.length;i++){
                $(ele2).append("<option value='"+name[i].id+"'>"+name[i].name+"</option>")
            }
            $(ele2).children().each(function(){
                if($(this).val() == num2){
                    $(this).attr("selected","selected");
                }
            })
        }else{
            var name = arr[id].city;
            for(var i=0;i<name.length;i++){
                $(ele2).append("<option value='"+name[i].id+"'>"+name[i].name+"</option>")
            }
        }
    }
}